﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KL.Store.Core.Domain;
using TN.Data;

namespace KL.Store.Data
{
    public class dbCart
    {
        #region Insert

        public static void Insert(int UserId, int ListOwnerUserId, long ListId, int ProductId, int Qty, Decimal Payment, bool ShowNameOnList, bool InstallmentSelected, DateTime Time, string variantValue, int AccountType)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Cart_Insert", new object[] { UserId, ListOwnerUserId, ListId, ProductId, Qty, Payment, ShowNameOnList, InstallmentSelected, Time, variantValue, AccountType });
        }

        #endregion

        #region VisitorToUser

        public static void VisitorToUser(int VisitorId, int UserId)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Cart_VisitorToUser", new object[] { VisitorId, UserId });
        }

        #endregion

        #region Update

        public static void Update(int UserId, int UserType, int ListOwnerUserId, long ListId, int ProductId, int Qty, Decimal Payment, bool ShowNameOnList, DateTime Time)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Cart_Update", new object[] { UserId, UserType, ListOwnerUserId, ListId, ProductId, Qty, Payment, ShowNameOnList, Time });
        }

        #endregion

        #region Delete

        public static void Delete(int UserId, int UserType, int ListOwnerUserId, long ListId, int ProductId)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Cart_Delete", new object[] { UserId, UserType, ListOwnerUserId, ListId, ProductId });
        }

        #endregion

        #region DeleteAll

        public static void DeleteAll(int UserId, int UserType)
        {
            SqlHelper.ExecuteNonQuery(dbParameters.dsnStore, "SPR_ESTORE_Cart_DeleteAll", new object[] { UserId, UserType });
        }

        #endregion

        #region GetList

        public static IList<Cart> GetList(int UserId, int UserType)
        {
            IList<Cart> objectList = new List<Cart>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Cart_List", objectList, new object[] { UserId, UserType });

            return objectList;
        }

        #endregion

        #region GetSummary

        public static CartSummary GetSummary(int UserId, int UserType)
        {
            IList<CartSummary> objectList = new List<CartSummary>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Cart_Summary", objectList, new object[] { UserId, UserType });

            return objectList.FirstOrDefault();
        }

        #endregion

        #region GetCargoDiscountSummary

        public static CargoDiscount GetCargoDiscountSummary(int ProductId)
        {
            IList<CargoDiscount> objectList = new List<CargoDiscount>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_CARGO_DISCOUNT_BY_PRODUCTID", objectList, new object[] { ProductId });

            return objectList.FirstOrDefault();
        }

        #endregion

        #region GetSummaryCargo

        public static CartSummaryCargo GetSummaryCargo(int UserId, int UserType, short CargoId, short SelectedCityId, decimal CreditCardDiscount, decimal TransferDiscount, bool CargoCalculateForSameProduct)
        {
            IList<CartSummaryCargo> objectList = new List<CartSummaryCargo>();
            SqlHelper.FillList(dbParameters.dsnStore, "SPR_ESTORE_Cart_Summary_Cargo", objectList, new object[] { UserId, UserType, CargoId, SelectedCityId, CreditCardDiscount, TransferDiscount, CargoCalculateForSameProduct });

            return objectList.FirstOrDefault();
        }

        #endregion

        #region CreateOrder

        public static int CreateOrder(int UserId, int UserType, string PaymentType, DateTime Zaman, bool InvoiceWithOrder, int CreateUser, decimal CommissionRate, decimal CampaignCommissionRate, decimal CreditCardDiscount, decimal TransferDiscount, int CargoId, decimal CargoPrice, decimal ListCargoPrice, decimal TransportPrice, bool TransportAvailable, decimal InstallationPrice, bool InstallationAvailable, short SelectedCityId, string OrderComment)
        {
            return (int)SqlHelper.ExecuteScalar(dbParameters.dsnStore, "SPR_ESTORE_Cart_Order_Create_v3", new object[] { UserId, UserType, PaymentType, Zaman, InvoiceWithOrder, CreateUser, CommissionRate, CampaignCommissionRate, CreditCardDiscount, TransferDiscount, CargoId, CargoPrice, ListCargoPrice, TransportPrice, TransportAvailable, InstallationPrice, InstallationAvailable, SelectedCityId, OrderComment });
        }

        #endregion

        #region CreateManualPos

        public static int CreateManualPos(string FirstName, string LastName, string TCKimlik, string Mobile, string CardOwnerName, string CardNumber, string BankName, string OrderNo, decimal OrgPayment, decimal Payment, int Installment, DateTime CreateDate, string IpAddress)
        {
            return (int)SqlHelper.ExecuteScalar(dbParameters.dsnStore, "SPR_ESTORE_Manual_Pos_Create", new object[] { FirstName, LastName, TCKimlik, Mobile, CardOwnerName, CardNumber, BankName, OrderNo, OrgPayment, Payment, Installment, CreateDate, IpAddress });
        }

        #endregion
    }
}
